<template>
    <div ref="body">
        <div style="height:30px;margin-top:3px" v-if="!disabledForStop">
            <Button type="primary" style="" @click="handleAdd">录入</Button>
        </div>
        <div style="margin-top:10px ">
            <vxe-table border
                       auto-resize
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       highlight-hover-row
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :data="tableData">
                <vxe-table-column field="ssba0001_name" title="收入所属 " align="center" min-width="100"/>
                <vxe-table-column field="ssba0010_name" title="收入类型" align="center" min-width="200"/>
                <vxe-table-column field="ssba0011_name" title="收入详细分类" align="center" min-width="200"/>
                <vxe-table-column field="ssba0012_name" title="收入计算方式" align="center" min-width="200"/>
                <vxe-table-column field="ssba0006" title="月收入金额" align="center" min-width="100"/>
                <vxe-table-column title="操作" align="center" fixed="right" min-width="200">
                    <template #default="{row}">
                        <Button type="info" size="small" @click="handleEdit(row)" v-if="!disabledForStop">编辑</Button>
                        <Button type="error" size="small" @click="handleDelete(row.id)" style="margin-left: 5px" v-if="!disabledForStop">删除
                        </Button>
                        <Button type="success" size="small" @click="handleDetail(row)" style="margin-left:5px">详情
                        </Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>

        <ss11003-modal ref="modalForm" @ok="modalFormOk" :type="17"/>
        <div style="height:40px;line-height:40px;margin-top:10px;text-align: center ">
            <Button @click="prevStep">上一步</Button>
            <Button type="primary" @click="nextStep" style="margin-left:20px" :loading="btnLoading">下一步
            </Button>
        </div>
    </div>
</template>

<script>
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import Ss11003Modal from '../ss11_create_steps/modules/Ss11003Modal'
    import {getAction, postAction} from '@/api/request'

    export default {
        name: "application3",
        mixins: [CommonMixin],
        components: {Ss11003Modal},
        data() {
            return {
                url: {
                    list: "/api/ac/subsistence/ss17003Service/getPageList",
                    delete: "/api/ac/subsistence/ss17003Service/deleteData",
                    check: "/api/ac/subsistence/ss17003Service/updateAndCheck",
                },
                Loading: true,
                queryParam: {
                    azcp0500: this.$parent.familyInfo.ss17001Id,
                    azdf0007: this.$parent.familyInfo.azdf0007,
                },
                btnLoading: false,
                disabledForStop:false,
            }
        },
        methods: {
            prevStep() {
                this.$emit('prevStep');
            },
            nextStep() {
                var url = this.url.check;
                this.btnLoading = true;
                var that = this;
                postAction(url, {azcp0500: this.$parent.familyInfo.ss17001Id}).then((res) => {
                    if (res.data.errcode == 0) {
                        this.$emit('nextStep')
                    } else {
                      if (res.data.errmsg.indexOf("重新计算") != -1) {
                        this.$Modal.error({
                          title: '提示',
                          content: res.data.errmsg,
                          onOk:this.loadData()
                        });
                      } else {
                        that.$Message.error(res.data.errmsg);
                      }
                    }
                }).finally(() => {
                    that.btnLoading = false;
                });
            },
        },
        created() {
            this.loadData();
            let that = this;
            //如是停救，operationType=300,则页面不可编辑
            if (that.$parent.familyInfo.ssca0016 == '300' || that.$parent.familyInfo.ssca0016 == '500' || that.$parent.familyInfo.ssca0016 == '501') {
                that.disabledForStop = true
            } else if (that.$parent.familyInfo.yjab0012 == '01' || that.$parent.familyInfo.yjab0012 == '02' || that.$parent.familyInfo.yjab0012 == '04') {
            //预警处置 已处置、维持现状、停救 不可编辑数据
                that.disabledForStop = true
            }
        },
    }
</script>

<style scoped>

</style>
